Hello and welcome back.
So in the last session we learned about four loops.
And now in this session we want to increase the functionality or the flexibility of our followers by
introducing the key words continue.
Break and pass.
So first of all let's create a list L with the elements 1 3 5 7 10 11 13 14 and 15.
What we want to do now we want to find the first even element an hour.
So what does even means that even means that I am modulo 2 equals zero.
We are introducing a fault of every element an error.
And then we are having an if statement if I model two is zero.
Then please print me the first even elements X and this element is odd.
Then please print me the elements at so let's have a look what we get here.
And here we get.
Okay.
One is up 3 Assad fighters not seven Assad.
Then the first element is 10 first even element.
But now you can see that iteration goes on until the very last element 15.
But what we actually wanted we wanted to determine the first element that is even and we do not care
about all any other elements that comes after the first even element.
And therefore we can here include the keyboard break.
So let's execute again.
They can see that the iteration stops once we have reached the first even element.
So what Python is doing here it iterate over the list.
And once our condition is met once so tense our first even element we print it and then break means
that we completely stop the iteration here.
All right.
We are only interested in the first even element we do not care about what elements so we don't want
to print out that let's for example say one is up and.
Yeah.
What we can do B can instead of having here the action print the element is what we can just say pass
or do nothing.
If an element is not and they can see it the only message the only result we get is that the first element
is 10 and even we we don't actually need here hear the complete s statement so if you just delete it
then it also works.
So now maybe you're asking yourself why do we need the pass statement.
I mean here we just deleted the whole s statement.
But let's assume we want to have the if statement the other way around.
So first of all we want to check if the element is art.
And in this case we just want to do nothing.
And if it's not art we want to print the very first even element and let's run the cell here and you
see it still works because here we are saying if the element is art then pass.
But what if we.
But what if we completely cross out paths and just have nothing here.
So if the element is up I do not care.
I'm not interested in again error message so far a statement we always have to define an action and
if you want to do nothing the past keyword is just a fill about which we need.
Otherwise we get an error message.
All right so we'll have a better understanding how the path keyword works.
We are just here having the same code.
But after our past keyword we say OK.
Even if our element is Art please print me the element and then we get one two three five seven and
then the first element even element is 10.
So maybe you want to print out all other elements but what if we don't want to print out all elements
so we are checking if an element is up and if it's art we are just wanting to go to the next element
and they are the keyword continue comes in to play.
So instead of having pass here we have continue and still we have printed.
But let's look if the behavior is different.
And here you can see we are just having the statement the first even element is 10.
So what Python does here.
It checks whether an element is odd and if it's art continuum means please go to the next element do
nothing and go to the next element even don't print it.
So that's actually the difference between past and continue.
So continuous is a keyword saying that please go to the next element and pass is just a keyword for
please do nothing.
And to make it a little bit more clear.
So let's assume we still want to find the first even element.
But for whatever reason we want to exclude 10.
As a result that's the here.
So this is the code we already know.
So if two is even then please print the first even elements x y z and then please break the if you want
to exclude that we get 10.
We have to introduce another if statement saying if I equals 10 please continue.
So please ignore if 10 this and minus because I don't want to have 10 as a result
so this gets me here 14 as a final result.
So the first even element is 14 because I just ignore 10.
All right so this is it for the time being.
And I hope to you in the next session by.